<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-page-container">
  <a [routerLink]="['..']" class="gv-back-link"><small><< Back to bot detection plugins</small></a>
  <h1>{{botDetection.name}}</h1>
  <div fxLayout="row">
    <div fxLayout="column" fxFlex="70">
      <form #botDetectionForm="ngForm">
        <div class="gv-form-section">
          <mat-form-field appearance="outline" floatLabel="always">
            <mat-label>Name</mat-label>
            <input matInput type="text" placeholder="Name" name="name" [(ngModel)]="botDetection.name" required [readonly]="!editMode">
            <mat-hint>Bot detection name</mat-hint>
          </mat-form-field>
          <mat-form-field appearance="outline" floatLabel="always">
            <mat-label>Detection type</mat-label>
            <input matInput type="text" placeholder="Detection type" name="detectionType" [(ngModel)]="botDetection.detectionType" required disabled>
            <mat-hint>Type of bot detection</mat-hint>
          </mat-form-field>
        </div>

        <div class="gv-form-section">
          <div class="gv-form-section-title">
            <h5>Configuration</h5>
            <mat-divider></mat-divider>
          </div>
          <div>
            <bot-detection-form *ngIf="botDetection" [botDetectionConfiguration]="botDetectionConfiguration" [botDetectionSchema]="botDetectionSchema" (configurationCompleted)="enablebotDetectionUpdate($event)"></bot-detection-form>
          </div>
        </div>

        <div fxLayout="row" *ngIf="editMode">
          <button mat-raised-button [disabled]="(!botDetectionForm.valid || botDetectionForm.pristine) && (!configurationIsValid || configurationPristine) && !formChanged" (click)="update()">SAVE</button>
        </div>
      </form>

      <div *hasPermission="['domain_bot_detection_delete']" class="gv-page-delete-zone" fxLayout="column">
        <p>This operation cannot be undone.</p>
        Configuration will be deleted, applications will not be able to use this bot dection plugin anymore.
        <div class="gv-page-delete-button" fxLayout="row">
          <span fxFlex></span>
          <button mat-raised-button color="warn" (click)="delete($event)">DELETE</button>
        </div>
      </div>
    </div>
    <div class="gv-page-description" fxFlex="30">
      <h3>Bot detection</h3>
      <div class="gv-page-description-content">
        <p>
          Bot Detection plugins protect your applications against bots. Protected pages are:
        </p>
        <ul>
          <li>Sign-In</li>
          <li>Sign-Up</li>
          <li>Forgot Password</li>
        </ul>
      </div>
      <div *ngIf="botDetection.type == 'google-recaptcha-v3-am-bot-detection'" class="bot-protection-settings-description">
        <h5>Integrate Google reCaptcha v3 in your pages</h5>

        <small>1. Import the JavaScript API</small>

        <div class="code">
          <button mat-icon-button matSuffix matTooltip="Copy to clipboard" ngxClipboard [cbContent]="getSnippetImportJS()" (cbOnSuccess)="valueCopied('Copied to clipboard')" (click)="$event.preventDefault();">
            <mat-icon>content_copy</mat-icon>
          </button>
          <pre style="white-space: normal;">
            <![CDATA[
              {{getSnippetImportJS()}}
            ]]>
          </pre>
        </div>

        <small>2. Call reCAPTCHA service before submit the form</small>

        <div class="code">
          <button mat-icon-button matSuffix matTooltip="Copy to clipboard" ngxClipboard [cbContent]="getSnippetCallService()" (cbOnSuccess)="valueCopied('Copied to clipboard')" (click)="$event.preventDefault();">
            <mat-icon>content_copy</mat-icon>
          </button>
          <textarea class="mdc-text-field__input" rows="18" [disabled]="true" aria-label="Label">{{getSnippetCallService()}}</textarea>
        </div>

        <p class="bot-protection-settings-description-contextual-help">For more information about Google reCAPTCHA v3 integration see <a href="https://developers.google.com/recaptcha/docs/v3">the official documentation</a></p>


      </div>
    </div>
  </div>
</div>
